package ecarx.com.cn.ecarxproject.business.bluetooth;

import android.bluetooth.BluetoothDevice;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;

/**
 * Created by zhanghao on 2016/10/18.
 */

public class BluetoothConnectActivityReceiver extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {
        if (intent.getAction().equals(
                "android.bluetooth.device.action.PAIRING_REQUEST")) {
            BluetoothDevice btDevice = intent
                    .getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);

            // byte[] pinBytes = BluetoothDevice.convertPinToBytes("1234");
            // device.setPin(pinBytes);
            Log.i("tag11111", "ddd");
            try {
                BlueAdmin.setPin(btDevice.getClass(), btDevice, "0000"); // 手机和蓝牙采集器配对
                BlueAdmin.createBond(btDevice.getClass(), btDevice);
                BlueAdmin.cancelPairingUserInput(btDevice.getClass(), btDevice);

            } catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
    }
}
